home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 020 / amigatoatari / longio.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  2KB  |  125 lines

  1. #include <stdio.h>
  2. #include "convert.h"
  3.  
  4. extern long filpos;
  5. extern int debug;
  6. extern int printing;
  7. extern char buf[];
  8.  
  9.  
  10. /*
  11.  * Get a longword or complain about premature EOF
  12.  *
  13.  */
  14. getlong(fd, p_lw)
  15. int fd;
  16. long *p_lw;
  17. {
  18.     if (readlong(fd, p_lw) == EOF)
  19.     panic("Premature EOF getting longword");
  20.     return OK;
  21. }
  22.  
  23.  
  24. /*
  25.  * Read 68000 longword from file,
  26.  * stuff it into '*p_lw' in the
  27.  * host machine's longword format.
  28.  *
  29.  */
  30. readlong(fd, p_lw)
  31. int fd;
  32. long *p_lw;
  33. {
  34.     char buf[4], *out;
  35.     int i;
  36.  
  37.     out = (char *)p_lw;
  38.     if (read(fd, buf, 4) != 4)        /* probably end of file */
  39.     return EOF;
  40.  
  41.     filpos += 4;
  42.     /*
  43.      * 8086/8088 conversion
  44.      * hh hl lh ll ==> ll lh hl hh
  45.      */
  46.     out[0] = buf[3];
  47.     out[1] = buf[2];
  48.     out[2] = buf[1];
  49.     out[3] = buf[0];
  50. }
  51.  
  52.  
  53. /*
  54.  * Write word to file,
  55.  * in 68000 format.
  56.  */
  57. writeword(fd, w)
  58. int fd;
  59. unsigned int w;
  60. {
  61.     char buf[2], *out;
  62.  
  63.     out = (char *)&w;
  64.     buf[0] = out[1];
  65.     buf[1] = out[0];
  66.     if (write(fd, buf, 2) != 2)
  67.     panic("Write error (word)");
  68. }
  69.  
  70.  
  71. /*
  72.  * Write longword to file, in
  73.  * 68000 format.
  74.  */
  75. writelong(fd, lw)
  76. int fd;
  77. long lw;
  78. {
  79.     char buf[4], *out;
  80.     int i;
  81.  
  82.     out = (char *)&lw;
  83.     buf[0] = out[3];
  84.     buf[1] = out[2];
  85.     buf[2] = out[1];
  86.     buf[3] = out[0];
  87.  
  88.     if (write(fd, buf, 4) != 4)
  89.     panic("Write error (longword)");
  90. }
  91.  
  92.  
  93. /*
  94.  * Read-and-write (copy from one
  95.  * file to another).
  96.  */
  97. randw(ifd, count, ofd)
  98. int ifd;
  99. long count;
  100. int ofd;
  101. {
  102. if(debug)printf("~ randw(%d, %ld, %d)\n", ifd, count, ofd);
  103.     for (; count > BUFFERSIZE; count -= BUFFERSIZE)
  104.     randw(ifd, BUFFERSIZE, ofd);
  105.     if (read(ifd, buf, (int)count) != (int)count)
  106.     panic("Read error.");
  107.     if (write(ofd, buf, (int)count) != (int)count)
  108.     panic("Write error.");
  109. }
  110.  
  111.  
  112. /*
  113.  * Write single byte to file
  114.  */
  115. emit(c, fd)
  116. int c;
  117. int fd;
  118. {
  119.     char cc;
  120.  
  121.     cc = (char)c;
  122.     if (write(fd, &cc, 1) != 1)
  123.     panic("Emit write error.");
  124. }
  125.